﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowTarget : MonoBehaviour
{
    public Transform player1;              //玩家1
    public Transform player2;              //玩家2
    private Vector3 offset;                //距离差值
    private new Camera camera;             //相机

    // Start is called before the first frame update
    void Start()
    {
        camera = this.GetComponent<Camera>();
        offset = transform.position - (player1.position + player2.position)/2;
    }

    // Update is called once per frame
    void Update()
    {
        if(player1 == null || player2 == null) return;
        transform.position = (player1.position + player2.position)/2 + offset;
        float distance = Vector3.Distance(player1.position, player2.position);
        float size = distance * 0.354f;
        camera.orthographicSize = size;
    }
}
